parent pom 定义你的项目模型,包括构建方式,项目环境,项目依赖,输出JavaDoc,发布source源码等等,怎样去编写一份parent pom,这里是一个现成的并正在某些项目中使用到的:点击查看GitHub源码

peaceful-basic-platform

A best global parent pom file , you can use it in jar or war project as your maven parent pom setting

<parent>
        <groupId>com.peaceful</groupId>
        <artifactId>peaceful-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
</parent> 

peaceful-parent

The basic configuration for build setting

  1. project build coding:UTF-8

  2. maven repositories:repo2

  3. default profiles: devtestproduct. The pom think project should has three running env or build env:dev、test、product. you can specify the environment by :

    
    `mvn -Penv[test][product]  compile[deploy][jetty:run]`
      

    The default env is dev, you can get the env value in pom by ${project.environment} and in Java code by invoke Application.getRunningMode()

setting build plugin

  1. buildnumber-maven-plugin:1.3 phase:validate desc:use timestamp as build version,you can get the version value by ${timestamp}
    in pom.xml and get the value in Java code by invoke Application.getBuildVersion()

  2. maven-jar-plugin:2.6

  3. maven-compiler-plugin:3.3

  4. maven-war-plugin:2.0.2

  5. maven-resources-plugin:2.7

  6. maven-source-plugin:2.4 phase:deploy

  7. maven-javadoc-plugin:2.9.1 phase:deploy

  8. maven-surefire-plugin:2.7 desc: default skip test

  9. yuicompressor-maven-plugin:1.5.0 desc:compress style file: .js .css

  10. jetty-maven-plugin:8.1.8.v20121106 desc: start web project in jetty, default port 8888,you can change web port in your pom to override Settings

       <properties>        
           <jetty.stop.port>9999</jetty.stop.port>
           <jetty.run.port>8888</jetty.run.port>
       </properties>

setting dependencies

  1. log:slf4j log4j perf4j

  2. test:junit

  3. common tools:guava、commons-lang3、httpclient

  4. json:fastjson

  5. web:jstl、javaee-api

  6. db:mysql、c3p0

  7. framework:spring、springMvc、mybatis

peaceful-common-utils

Cooperate with the parent pom configuration files, can read building basic information, such as building time, version number, running environment of the project

The parent pom define 3 kinds of profile:devtestproduct。If your project use the pom as parent pom,you need add peaceful-common-utils dependency in your pom file.

<dependency>
    <groupId>com.peaceful</groupId>
    <artifactId>peaceful-common-utils</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

The peaceful-common-utils will read your build info into application.properties.

get build version

Application.getVersion()

get running mode

Application.getRunningMode()
...
Application.isTest()
Application.isProduct()
Application.isDev() 

get Running time

# you need invoke Application.loadToJVM() when your application start
Application.getRunningTime()

wangjuntytl
292 声望10 粉丝

互联网从业者